﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Admin_ReportDesign_View.aspx.cs" Inherits="Xiaov.SmartWeb.Application.PluginSrc.StatisticalSystem.ReportDesign.Admin_ReportDesign_View" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
       <link rel="stylesheet" type="text/css" href="/Resources/easyui-1.32/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="/Resources/easyui-1.32/themes/icon.css"/>
    <link rel="stylesheet" type="text/css" href="/Resources/xiaovcn/css/main.css"/>
    <script type="text/javascript" src="/Resources/easyui-1.32/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/Resources/easyui-1.32/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/common.js"></script>
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/usercheck.js"></script>
    <style>
        .pselectedcell {
        background-color:#b7efbf;
        }
        .pselectedarea {
        background-color:#b6ff00; border:solid 1px red;
        }
        .pselectedarea td {
            border:solid 1px red;
        }
        .phidden{
            background-color:rgba(196, 220, 250, 0.65);
        }
        .plock {
            background-color:#ffd1c9;
        }
        .pexp {
             background-color:#fbcaff;
        }
    </style>
    <script>
        var pre = null;
        var inputfomate = "<input type='text' style='padding:0px;'/>";
        var tdinputselection = "";
        var cellislock = "0";
        var selectedcolindex =0; // 表头选择列
        var selectedrowindex = 0; //表头选择行
        //定义区域
        var is_selected_area_start = 1;
        var area_c1, area_c2, area_r1, area_r2;
        //隐藏列
        var hidden_column = '<%=xmlConfig.HiddenColumn%>';
        var hidden_row = '<%=xmlConfig.HiddenRow%>';
        var lock_column = '<%=xmlConfig.NotAllowEditColumn%>';
        var lock_row = '<%=xmlConfig.NotAllowEditRow%>';
        var lock_area = '<%=xmlConfig.NotAllowEditCells%>';
                
        function set_selected_area(rindex,cindex) {
            if (is_selected_area_start == 1) {
                //选择起始单元格
                $('.pselectedarea').removeAttr('style');
                $('.pselectedarea').removeClass('pselectedarea');
                
                area_r1 = rindex;
                area_c1 = cindex;
            }
            else {
                //设置终止单元格
                area_c2 = cindex;
                area_r2 = rindex;
                //重新排列顺序
                if (area_r1 > area_r2) {
                    var v = area_r1;
                    area_r1 = area_r2;
                    area_r2 = v;
                }
                if (area_c1 > area_c2) {
                    var v = area_c1;
                    area_c1 = area_c2;
                    area_c2 = v;
                }
                //添加区域色块
                lockArea(area_c1, area_c2,area_r1,area_r2);
            }
        }

        function lockArea(c1, c2, r1, r2) {            
            for (var t = r1; t <= r2; t++) {
                for (var j = c1 ; j <= c2; j++) {
                    var q = $('#datagrid-row-r3-2-' + t + " td:eq(" + j + ")");
                    q.addClass("pselectedarea");
                    q.attr('style', 'border:solid 1px red;');
                }
            }
        }

        function bindheaderClick() {
            //绑定表头可编辑
            $("#gridcontent .datagrid-header-row td div").click(function (e) {
                //移除焦点
                $('.pselectedcell').removeClass(); 
                //当前选中的列
                selectedcolindex = $(this).parent().index();
                //当前的行
                selectedrowindex = $(this).parent().parent().index();
                //设置焦点
                $(this).parent().addClass('pselectedcell');
                //编辑
                switchtdinput(this);                
            });
        }

        function bindRightMenu() {
            $('#gridcontent .datagrid-header-row').bind('contextmenu', function (e) {
                e.preventDefault();
                $('#header_rightmenu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
            $('#gridcontent .datagrid-body .datagrid-row').bind('contextmenu', function (e) {
                e.preventDefault();
                $('#body_rightmenu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            });
        }
        
        $(document).ready(function () {
            //绑定属性面板 初始化
            $('#pg').propertygrid({
                url: 'Json/GetGridConfig.aspx?tn=<%=tn%>&xml=<%=xml%>',
                showGroup: true,
                showHeader: true,
                scrollbarSize: 0
            });

            //init
            

            $('#tt').datagrid({
                singleSelect:true,
                onClickCell: function (index, field, value) {
                    //单击单元格时发生
                    //$(".pselectedcell").removeClass(); //焦点色块
                    selectedcellid = getId_by_index_field(index, field);
                    //$("#" + selectedcellid).parent().removeClass('pselectedcell');
                    var cindex = $('#' + selectedcellid).parent().index();
                    set_selected_area(index, cindex);
                    switchtdinput($("#" + selectedcellid));          //编辑          
                    changepropertygrid(index, field); //设置当前选择情况
                    //$("#" + selectedcellid).parent().addClass('pselectedcell');
                    //当前是否结束点
                    if (is_selected_area_start == 1) {
                        is_selected_area_start++;
                    }
                    else {
                        is_selected_area_start = 1;
                    }
                },
                onLoadSuccess: function (val) {    
                    LockC();          //锁定Column
                    LockR();          //锁定Row
                    LockA();         //锁定区域
                    HiddenC();    //隐藏Column
                    HiddenR();    //隐藏Row
                   
                }
            });
            bindheaderClick();
            bindRightMenu();
            $("#header_rightmenu").menu({
                onClick: function (item) {
                    header_op(selectedrowindex, selectedcolindex, item.name);                    
                }
            });

            $("#body_rightmenu").menu({
                onClick: function (item) {
                    body_op(selectedrowindex, selectedcolindex, item.name);
                }
            });
        });

        function changepropertygrid(index, field) {
            var id = getId_by_index_field(index, field);
            var cindex = $('#' + id).parent().index();
            $('#datagrid-row-r2-2-7 td:eq(1) div').html(field);
            $('#datagrid-row-r2-2-8 td:eq(1) div').html(index);
            $('#datagrid-row-r2-2-9 td:eq(1) div').html('' + index + ',' + cindex + '');
            if (is_selected_area_start == 2) {
                $('#datagrid-row-r2-2-10 td:eq(1) div').html(area_c1 + "," + area_c2 + "," + area_r1 + "," + area_r2);
            }
            else {
                $('#datagrid-row-r2-2-10 td:eq(1) div').html("");
            }
        }

        //右键菜单方法
        function header_op(rindex, cindex, name) {
            var len = $('#datagrid-row-r3-2-0 td').length; // 列总数
            var emptytd = "<td style='height:24px;'><div class='datagrid-cell'><span>&nbsp;</span></div></td>";

            //删除
            if (name == 'header_menu-delete') {
                if ($('#gridcontent .datagrid-view2 .datagrid-header-row').length > 1) {
                    $('#gridcontent .datagrid-view2 .datagrid-header-row').eq(rindex).remove();
                }
                else
                    alert('再删就没有了');
            }
            //上插
            else if (name == 'header_menu-insert_top')
            {
                var html = "";     
                for (var i = 0; i < len; i++)
                {
                    html += emptytd;
                }            
                $('#gridcontent .datagrid-view2 .datagrid-header-row').eq(rindex).before("<tr class='datagrid-header-row'>" + html + "</tr>");
            }

            //下插
            else if (name == 'header_menu-insert_down') {
                var html = "";
                for (var i = 0; i < len; i++) {
                    html += emptytd;
                }
                $('#gridcontent .datagrid-view2 .datagrid-header-row').eq(rindex).after("<tr class='datagrid-header-row'>" + html + "</tr>");
            }
            //右 合并
            else if (name == 'header_menu-merge_right') {
                //rindex cindex
                //删除下一个 并将当前格 和 下一格的colspan加和 赋值给当前格 
                var nextcell = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex + 1) + ')').length;

                if (nextcell == 0) {
                    alert('不能再合并了'); return false;
                }

                var xspan1 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('colspan');
                var xspan2 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex + 1) + ')').attr('colspan');

                if (typeof (xspan1) == "undefined") {
                    xspan1 = 1;
                }
                if (typeof (xspan2) == "undefined") {
                    xspan2 = 1;
                }
                
                $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex + 1) + ')').remove();
                //alert(cindex + 1);
                $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('colspan', Number(xspan1) + Number(xspan2));
                
                
            }
            //下 合并
            else if (name == 'header_menu-merge_down') {
                //行数
                var rowscount = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ')').length;
                //当前格的colspan & rowspan
                var xspan1 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('colspan');
                var yspan1 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('rowspan');
                if (typeof (xspan1) == "undefined") {
                    xspan1 = 1;
                }
                if (typeof (yspan1) == "undefined") {
                    yspan1 = 1;
                }
                //索引数
                var nextrowindex = Number(rindex) + Number(yspan1);
                if (nextrowindex > rowscount) {
                    alert('不能再合并了'); return false;
                }
                //下格的 col & row span
                var xspan2 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(nextrowindex) + ') td:eq(' + Number(cindex) + ')').attr('colspan');
                var yspan2 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(nextrowindex) + ') td:eq(' + Number(cindex) + ')').attr('rowspan');
                //先分析是否允许合并,为了实现简单，先假定只有colspan相等时才允许
                
                if (typeof (xspan2) == "undefined") {
                    xspan2 = 1;
                }
                if (typeof (yspan2) == "undefined") {
                    yspan2 = 1;
                }
                if (xspan1 == xspan2) {
                    //...判断下格是否是field : td dom含有field属性
                    var fieldname = $('#gridcontent .datagrid-view2 tr:eq(' + Number(nextrowindex) + ') td:eq(' + Number(cindex) + ')').attr('field');
                    var cell = $('#gridcontent .datagrid-view2 tr:eq(' + Number(nextrowindex) + ') td:eq(' + Number(cindex) + ')').html();
                    //上下合并 先移除下面的格
                    $('#gridcontent .datagrid-view2 tr:eq(' + Number(nextrowindex) + ') td:eq(' + Number(cindex) + ')').remove();
                    //将当前格的rowspan和下格rowspan相加
                    //如果 合并的不是title 而是field 则需要增加field属性 
                    //....获取下格的field和text

                  
                    if (fieldname)
                    {
                        $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('field', fieldname);
                        $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').html(cell);

                        $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ') div').html('<span>' + fieldname + '</span><span class=\'datagrid-sort-icon\'></span>');
                    }

                    $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('rowspan', Number(yspan1) + Number(yspan2));
                    
                }
                else {
                    alert('上下格形状不一致,无法合并');
                }


            }
            //拆分成列
            else if (name == 'header_menu-split') {
                
                //当前格的colspan & rowspan
                var xspan1 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('colspan');
                var yspan1 = $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').attr('rowspan');
                if (typeof (xspan1) == "undefined") {
                    xspan1 = 1;
                }
                if (typeof (yspan1) == "undefined") {
                    yspan1 = 1;
                }
                if (xspan1 > 1||yspan1>1) {
                   
                    //单元格重建
                    var html = "<td class='datagrid-header-row'><div class='datagrid-cell'></div></td>";
                   
                    //下面N行拆分
                    for (var t = 0; t < yspan1; t++) {
                        for (var i = 0; i < xspan1; i++) {
                            $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex + t) + ') td:eq(' + Number(cindex) + ')').after(html);
                        }
                    }
                    //如果xspan>1 移除该合并方格
                    $('#gridcontent .datagrid-view2 tr:eq(' + Number(rindex) + ') td:eq(' + Number(cindex) + ')').remove();
                } 
            }
            bindheaderClick();
            bindRightMenu();
            $('#tt').datagrid('fixColumnSize');                //修正尺寸
        }
  
        function body_op(rindex, cindex, name) {
            if (name == 'body_menu-area') {
                alert('show area');
            }
            if (name == 'body_menu-row') {
                alert('show row');
            }
            if (name == 'body_menu-column') {
                alert('show column');
            }
            if (name == 'body_menu-cell') {
                alert('show cell');
            }
        }

        //更新数据
        function SaveData() {
            var dwbm = $('#dwbm').combobox('getValue');
            var year = $('#year').combobox('getValue');
            var month = $('#month').combobox('getValue');
            var errorcount = $('.error').length;
            if (errorcount > 0) {
                alert('输入数据错误,请检查');
            }
            else {
                //更新数据   
                var r = $("tr[changed='1']").length;
                if (r > 0) {
                    var xml = "<DataRoot>";
                    for (var i = 0; i < r; i++) {
                        xml += "<Record>";
                        var c = $("tr[changed='1']:eq(" + i + ") td").length;
                        for (var j = 0; j < c; j++) {
                            var fd = $("tr[changed='1']:eq(" + i + ") td:eq(" + j + ") ").attr("field");
                            xml += "<" + fd + ">"
                            xml += $("tr[changed='1']:eq(" + i + ") td:eq(" + j + ") ").text();
                            xml += "</" + fd + ">";
                        }
                        xml += "</Record>";
                    }
                    xml += "</DataRoot>";
                    //alert(xml);
                    //提交到数据库 
                    $.ajax({
                        type: 'post',
                        url: '/PluginSrc/StatisticalSystem/SaveData.aspx',
                        data: { data: encodeURIComponent(xml), tn: '#DataGrid_Tn#', year: year, month: month, dwbm: dwbm },
                        datatype: 'html',
                        success: function (result) { ReloadGrid(); showmsger('数据保存成功'); },
                        error: function (result) { alert(result.responseText); },
                    });
                }
            }

        }

        function SetColumnDataType() {

            //列的数据类型
            var str = itypestring.split('|');

            var c = $('#datagrid-row-r3-2-0 td[field]');

            for (var j = 0; j < c.length; j++) {
                $('#datagrid-row-r3-2-0 td[field]:eq(' + j + ')').attr('itype', str[j]);
            }

        }


        function LockC() {
            if (lock_column != "NULL" && lock_column != "") {
                var rows = $('#gridcontent .datagrid-view2 .datagrid-body .datagrid-btable tbody tr').length;
                var str = lock_column.split(',');
                for (var j = 0; j < str.length; j++) {
                    for (var i = 0; i < rows; i++) {
                        $('#datagrid-row-r3-2-' + i + " td:eq(" + str[j] + ")").attr("lock", "1");
                        $('#datagrid-row-r3-2-' + i + " td:eq(" + str[j] + ")").addClass("plock");
                    }
                }
            }
            if (hidden_column != "NULL" && hidden_column != "") {
                var rows = $('#gridcontent .datagrid-view2 .datagrid-body .datagrid-btable tbody tr').length;
                var str = hidden_column.split(',');
                for (var j = 0; j < str.length; j++) {
                    for (var i = 0; i < rows; i++) {
                        $('#datagrid-row-r3-2-' + i + " td:eq(" + str[j] + ")").attr("lock", "1");
                        $('#datagrid-row-r3-2-' + i + " td:eq(" + str[j] + ")").addClass("phidden");
                    }
                }
            }
        }

        function LockR() {
            //$('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(0)').addClass('lockrow');
            if (lock_row != "NULL") {
                var rows = lock_row.split(',');
                for (var i = 0; i < rows.length; i++) {
                    $('#datagrid-row-r3-2-' + rows[i] + " td").attr("lock", "1");
                    $('#datagrid-row-r3-2-' + rows[i] + " td").addClass("plock");
                }
            }
        }

        function LockA() {
            //lock Area
            if (lock_area != "NULL" && lock_area != "") {
                var str = lock_area.split('|');
                for (var i = 0; i < str.length; i++) {
                    xy = str[i].split(',');
                    var x = xy[2];
                    var xspan = xy[1];
                    var y = xy[0];
                    var yspan = xy[3];
                    for (var t = x; t <= yspan; t++) {
                        for (var j = y ; j <= xspan; j++) {
                            var q = $('#datagrid-row-r3-2-' + t + " td:eq(" + j + ")");                            
                            q.addClass("plock");
                        }
                    }
                }
            }
        }

        function HiddenC() {
            if (hidden_column != "NULL" && hidden_column != "") {
                var str = hidden_column.split(',');
                for (var i = 0; i < str.length; i++) {
                    var f = $('#datagrid-row-r3-2-0 td:eq(' + str[i] + ')').addClass("phidden");
                    //$('#tt').datagrid('hideColumn', f);
                }
            }
        }

        function HiddenR() {
            if (hidden_row != "NULL" && hidden_row != "") {
                var str = hidden_row.split(',');
                for (var i = 0; i < str.length; i++) {
                    $('#datagrid-row-r1-1-' + str[i]).hide();
                    $('#datagrid-row-r1-2-' + str[i]).hide();
                }
            }
        }

        function getId_by_index_field(index, field) {
            var id = "datagrid-row-r3-2-" + index + " td[field='" + field + "'] div";
            //$("#"+id).addClass("selected");
            //var rowposition="datagrid-row-r3-2-"+index;
            return id;
        }

        //根据index和field判定单元格是否锁定
        function islock_by_index_field(index, field) {
            var r = $("#datagrid-row-r3-2-" + index + " td[field='" + field + "']").attr("lock");
            if (r == "1")
                return true;
            else
                return false;
        }

        //根据行索引和列索引判定是否锁定
        function islock_by_index(rindex, cindex) {
            var r = $("#datagrid-row-r3-2-" + rindex + " td:eq(" + cindex + ")").attr("lock");
            if (r == "1")
                return true;
            else
                return false;
        }

        var pre = null;
        var inputfomate = "<input type='text' style='padding:0px;'/>";
        var tdinputselection = "";
        var cellislock = "0";

        function switchtdinput(obj) {

            if (pre) {
                doinpleave(pre);
            }
            var width = $(obj).width() * 1.0;
            var objtxt = $.trim($(obj).text());
            $(obj).html($(inputfomate).val(objtxt));
            pre = $(obj).find('input').css("border", "1px solid red").width(width)[0];
            $(obj).find('input').trigger("focus").trigger("select");
            //$(obj).find('input').css("class","easyui-validatebox");
            $(obj).find('input').click(function (event) {
                stopevent(event);
                return false;
            }).blur(function (event) {
                inpleave(event, this);
            }).keypress(function (event) {
                stopevent(event);
            }).keyup(function (event) {
                return setpreornext(event, this);
            }).keydown(function (event) {
                tdinputselection = getSelectedText();
                stopevent(event);
                if (event.ctrlKey && event.keyCode == 86) {

                    //从剪贴板粘贴数据 =========== by xiaovcn
                    var clipText = window.clipboardData.getData('Text');
                    if (clipText != null) {
                        //去除末尾的\r\n以免出现空值 从excel复制默认总是有一个回车 原因?
                        var p = clipText.lastIndexOf(String.fromCharCode(13) + String.fromCharCode(10));
                        if (p != -1) {
                            clipText = clipText.substring(0, p);
                        }
                        //用\r\n分割数据串
                        clipRows = clipText.split(String.fromCharCode(13) + String.fromCharCode(10));

                        for (i = 0; i < clipRows.length; i++) {
                            //用\t分割数据
                            clipRows[i] = clipRows[i].split(String.fromCharCode(9));
                        }
                        //写入html
                        paste(event, this, clipRows);
                    }
                    //从剪贴板粘贴数据 ===========end by xiaovcn
                }
            });

        }

        //根据field获取当前的列索引 
        function get_colindex_byfield(field) {
            var c = "[field='" + field + "']"
            var s = $('#datagrid-row-r3-2-0 td' + c).index();
            return s;
        }

        //根据id返回行索引
        function get_rowindex_byid(obj) {
            return obj.substring(selectedcellid.lastIndexOf('-') + 1)
        }

        //根据行索引和列索引获取jquery选择器 为复制粘贴excel数据
        function get_cell_selector_byindex(r, c) {
            return $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + r + ') td:eq(' + c + ') div')
        }

        function get_header_cell_selector_byindex(r, c) {
            return $('.datagrid-view2 .datagrid-header .datagrid-htable tbody tr:eq(' + r + ') td:eq(' + c + ') div')
        }

        //根据行索引和列索引 设置changed=1
        function set_cell_changed(r, c) {
            $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + r + ')').attr('changed', '1');
            $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + r + ') td:eq(' + c + ') div').attr('changed', '1');
        }

        //根据行索引和列索引 移除changed
        function set_cell_Nochanged(r, c) {
            $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + r + ') td:eq(' + c + ') div').removeAttr('changed');
        }

        function set_cell_NoError(r, c) {
            $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + r + ') td:eq(' + c + ') ').removeClass('error');
        }

        function set_cell_Error(r, c) {
            $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + r + ') td:eq(' + c + ') ').addClass('error');
        }

        //粘贴数据
        function paste(event, obj, clipRows) {
            var rindex = selectedrowindex;
            for (i = 0; i < clipRows.length; i++) {
                var cindex = selectedcolindex;
                for (j = 0; j < clipRows[i].length; j++) {
                    //当前位置是input  其他位置 是div
                    var value = trim(clipRows[i][j]);

                    //判定当前单元格是否锁定
                    var l = false;
                    l = islock_by_index(rindex, cindex);
                    //数据合法性
                    var ck = false;
                    ck = checkvalidate(value, itypes[cindex]);
                    if (!l) {
                        //设置值  先不管合法不合法 粘完再判定
                        set_cell_NoError(rindex, cindex);
                        get_cell_selector_byindex(rindex, cindex).text(value);
                        if (!ck) {
                            set_cell_Error(rindex, cindex);
                        }
                        set_cell_changed(rindex, cindex);//设置changed属性1
                    }
                    //alert(rindex+"="+cindex);
                    cindex = getNextNotHiddenColumn(rindex, cindex, itypes.length); //列索引                               
                }
                rindex = getNextNotHiddenRow(rindex, cindex, itypes.length); //行索引
            }
        }

        function trim(str) {

            return str.replace(/(^\s*)|(\s*$)/g, "");

        }


        function stopevent(event) {
            event.stopPropagation();
        }

        function inpleave(event, obj) {
            stopevent(event);
            doinpleave(obj);
        }

        function doinpleave(obj) {
            if (!obj) return;
            var val = $(obj).val();
            var $par = $(obj).parent()[0];
            $($par).text(val);
            pre = null;
        }

        function getSelectionStart(o) {
            if (o.createTextRange) {
                var r = document.selection.createRange().duplicate();
                r.moveEnd('character', o.value.length);
                if (r.text == '') return o.value.length
                return o.value.lastIndexOf(r.text);
            } else return o.selectionStart;
        }

        function getSelectedText() {
            if (window.getSelection) {
                return window.getSelection().toString();
            }
            else if (document.getSelection) {
                return document.getSelection();
            }
            else if (document.selection) {
                return document.selection.createRange().text;
            }
        }

        //是否为数字
        function isnum(obj) {
            if (obj == "" || obj == null)
                return true;
            else {
                var re = /^[0-9]+.?[0-9]*$/;
                if (!re.test(obj)) {
                    return false;
                }
                else {
                    return true;
                }
            }
        }
        //是否为字符串
        function isstring(obj) {
            //文本框中不能含有\n\n 1 单引号: ' \n 2 双引号: \" \n 3 竖 杠: | \n 4 尖角号: < > \n\n请检查输入
            var pattern = /^[^\|"'<>]*$/;
            if (pattern.test(obj))
                return true;
            else
                return false;
        }

        function checkvalidate(obj, itype) {
            var ckresult = false;
            if (itype == "System.String") {
                ckresult = isstring(obj);
            }
            if (itype == "System.Decimal") {
                ckresult = isnum(obj);
            }
            return ckresult;
        }


        function setpreornext(event, objThis) {
            // 输入合法性检查
            //var iii = get_colindex_byfield($(objThis).parent().parent().attr("field"));
            //alert(itype);

            //$(objThis).parent().parent().parent().attr('changed', 1);
            //var inputvalue = $(objThis).val();
            //根据type字符串来决定某列是什么数据类型
            //var ck = checkvalidate(inputvalue, itypes[iii]);
            //if (ck) {
                //移除error错误提示样式
                $(objThis).parent().parent().removeClass("error");
                var count = -1;
                var current;
                stopevent(event);
                var obj; //焦点移动到得位置
                //判断键盘动作keyCode 40=Down  38=UP  13=enter 37=left  39=right 9=Tab
                if (event.keyCode == 40 || event.which == 40 || event.keyCode == 38 || event.which == 38 || event.keyCode == 13 || event.which == 13 || event.keyCode == 37 || event.which == 37 || event.keyCode == 39 || event.which == 39) {

                    //当前的位置 objThis 为 单元格中的div datagrid-row-r3-2-rowindex
                    row = $(objThis).parent().parent().parent()[0].id;

                    nextrowindex = parseInt(row.substring(row.lastIndexOf('-') + 1)) + 1;

                    prerowindex = parseInt(row.substring(row.lastIndexOf('-') + 1)) - 1;

                    nextrow = row.substring(0, row.lastIndexOf('-') + 1) + nextrowindex;

                    prerow = row.substring(0, row.lastIndexOf('-') + 1) + prerowindex;

                    field = $(objThis).parent().parent().attr("field");

                    //var id="datagrid-row-r3-2-"+index+" td[field='"+field+"'] div";              

                    var downcell = "#" + nextrow + " td[field='" + field + "'] div";
                    var dc_l = "#" + nextrow + " td[field='" + field + "']";

                    var upcell = "#" + prerow + " td[field='" + field + "'] div";
                    var uc_l = "#" + prerow + " td[field='" + field + "']";

                    var thistd = "#" + row + " td[field='" + field + "']";

                    //alert(downcell);
                    //count = parseInt($(objThis).parent().data("i"));

                    var nc = null;

                    if (event.keyCode == 40 || event.which == 40) {
                        obj = $(downcell);//向下    
                        nc = $(dc_l).attr("lock");

                    } else if (event.keyCode == 38 || event.which == 38) {
                        obj = $(upcell);//向上
                        nc = $(uc_l).attr("lock");

                    } else if (event.keyCode == 13 || event.which == 13) {
                        obj = $(downcell);//回车--向下
                        nc = $(dc_l).attr("lock");

                    } else if (event.keyCode == 37 || event.which == 37) {
                        obj = $(thistd).prev("td").find("div");//向左
                        nc = $(thistd).prev("td").attr("lock");

                    } else if (event.keyCode == 39 || event.which == 39) {
                        obj = $(thistd).next("td").find("div");//向右
                        nc = $(thistd).next("td").attr("lock");
                    }
                    if (obj) {

                        //判定要移动目标是否锁定
                        if (nc == "1") {
                            cellislock = "1";
                        }
                        else {
                            cellislock = "0";
                        }
                        if (cellislock == "0") {
                            doinpleave(objThis);
                            switchtdinput(obj);
                        }
                    }
                }

                if (event.keyCode == 13 || event.which == 13)
                    return false;
                else
                    return true;
            //}
            //else {
            //    //输入框变色 提示
            //    $(objThis).parent().parent().addClass("error");
            //}
        }


        function setCJ() {
            var hcstr = hc.split(',');
            if (hcstr.length == 2) {
                var r = $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr').length;
                for (var i = 0; i < r; i++) {
                    var str = "";
                    var spacenum = $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + i + ') td:eq(' + hcstr[1] + ') div').text();

                    for (var j = 0; j < spacenum - 1; j++) {
                        str += '&nbsp;&nbsp;&nbsp;';
                    };
                    var txt = str + $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + i + ') td:eq(' + hcstr[0] + ') div').text();
                    $('.datagrid-view2 .datagrid-body .datagrid-btable tbody tr:eq(' + i + ') td:eq(' + hcstr[0] + ') div').html(txt);
                }
                //
            }
        }

        function showmsger(c) {
            $.messager.show({
                title: '操作提示',
                msg: c,
                timeout: 2000,
                showType: 'show'
            });
        }

        
    </script>
</head>
<body>
    <div id="cc" class="easyui-layout" style="height:500px;">     
   
   <div data-options="region:'east',iconCls:'icon-reload',title:'属性面板',split:true,collapsible:false,border:0" style="width:310px;">
       <table id="pg" style="width:300px; height:200px" fit="true"></table>  
   </div>  
 
 <div data-options="region:'center',title:'表格设计'" style="padding:5px;">
     <div style="background-color:#e0dbdb; padding:5px;">
         <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'">保存配置</a>  
         <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-reload'">重新加载</a>
         <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-cancel'">删除</a>
     </div>
     <div id="gridcontent">
      <asp:Literal ID="lt" runat="server"></asp:Literal>
     </div>

 </div>  
</div> 

        <%--Right menu by xiaovcn--%>
        <div id="header_rightmenu" class="easyui-menu" style="width:150px;display:none;">
        
        <div name="header_menu-insert_top">上插入行</div>
	    <div name="header_menu-insert_down">下插入行</div>
	    <div class="menu-sep"></div>
	    <div name="header_menu-merge_right">向右合并</div>
        <div name="header_menu-merge_down">向下合并</div>
        <div class="menu-sep"></div>
         <div name="header_menu-split">拆分</div>
	    
    </div>

       <div id="body_rightmenu" class="easyui-menu" style="width:150px;display:none;">
        
        <div name="body_menu-area">区域</div>
	    <div name="body_menu-column">列</div>	  
        <div name="body_menu-row">行</div> 
        <div name="body_menu-cell">单元格</div> 
        <div class="menu-sep"></div>	 
    </div>

</body>
</html>
